Skip to content

feat(tron-wallet-snap): route asset reads through Core AssetsController - #127

Open
ulissesferreira wants to merge 5 commits into
mainfrom
ulissesferreira/wpn-1497-core-adapter-routing-9863
Open

feat(tron-wallet-snap): route asset reads through Core AssetsController#127
ulissesferreira wants to merge 5 commits into
mainfrom
ulissesferreira/wpn-1497-core-adapter-routing-9863

Conversation

@ulissesferreira

@ulissesferreira ulissesferreira commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Continue with using only getAccountAssetByID, getAccountAssetsByIDs, getAccountAssetsByScope and getAccountAssets
  • Implement a new adapter responsible for offering the exact same functionality for reads but using the AssetsController

Jira

Test plan

  • yarn workspace @metamask/tron-wallet-snap run jest --no-coverage src/services/assets/
  • CI green
Open in Web Open in Cursor 

@cursor
cursor Bot force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch from bfa488d to 327dfab Compare August 5, 2026 18:29
@cursor
cursor Bot force-pushed the WPN-1497-messenger-plumbing branch 2 times, most recently from 6587ae2 to 9428a52 Compare August 5, 2026 19:34
@cursor
cursor Bot force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch 2 times, most recently from 6769ec9 to 4d766ab Compare August 5, 2026 19:34
@ulissesferreira ulissesferreira changed the title feat(tron-wallet-snap): route fungible reads through Core AssetsController feat(tron-wallet-snap): route asset reads through Core AssetsController Aug 6, 2026
@cursor
cursor Bot force-pushed the WPN-1497-messenger-plumbing branch from 9428a52 to 489bab0 Compare August 6, 2026 08:14
Base automatically changed from WPN-1497-messenger-plumbing to main August 6, 2026 08:31
@ulissesferreira

Copy link
Copy Markdown
Contributor Author

@cursoragent rebase with latest main

@cursor

cursor Bot commented Aug 6, 2026

Copy link
Copy Markdown

Rebased ulissesferreira/wpn-1497-core-adapter-routing-9863 onto latest main and force-pushed.

What happened during rebase:

  • Resolved conflict in .github/workflows/lint-build-test.yml — kept main’s upload-artifact@v7 / download-artifact@v8 (your branch had older pinned versions).
  • Dropped build: run workspace builds in topological-dev order — already on main.
  • Skipped feat(tron-wallet-snap): add Core messenger plumbing — already merged via feat(tron-wallet-snap): add Core messenger plumbing #95.

Result: 8 commits ahead of main (down from 11), including the core routing work and follow-up fixes.

PR #127 is updated: #127

Open in Web Open in Cursor 

@cursor
cursor Bot force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch from 4d766ab to af82730 Compare August 6, 2026 09:29
@ulissesferreira
ulissesferreira force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch 7 times, most recently from dbfa825 to 703eabc Compare August 6, 2026 12:39
@ulissesferreira
ulissesferreira marked this pull request as ready for review August 6, 2026 12:53
@ulissesferreira
ulissesferreira requested review from a team as code owners August 6, 2026 12:53
@MetaMask MetaMask deleted a comment from cursor Bot Aug 6, 2026
@ulissesferreira

Copy link
Copy Markdown
Contributor Author

@cursoragent make sure the CI is green

@cursor

cursor Bot commented Aug 6, 2026

Copy link
Copy Markdown

Taking a look!

Open in Web Open in Cursor 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how simple fetching assets will be. All calls are basically direct AssetsController calls and then, for now, we map the structure of it to minimize the amount of changes in the repository. In a future PR we will want to remove the mapping and use the structure from the AssetsController. One of the methods also returns a dictionary, purposefully, which we will refactor the existing codebase to use as well because that is the idiomatic way to do things, if you fetch by a collection of IDs it only makes sense you get them back in an easy to access way.

SNAPS_ASSETS_MIGRATION_FLAG_KEYS.tron,
);
return parseSnapsAssetsMigrationStage(flagValue);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the function from AssetsController to see which stage of the migration we are on and we simply read the feature flags from the shared RemoteFeatureFlagsProvider

@ulissesferreira
ulissesferreira force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch from 5fdb1d9 to 703eabc Compare August 6, 2026 14:15
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope"
"AssetsController:getAccountAssetsByScope",
"RemoteFeatureFlagController:getState"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a formatting fix

rawAmount: amount,
uiAmount: toUiAmount(amount, decimals).toString(),
iconUrl,
} as AssetEntity;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now this is needed because we haven't aligned all assetType from all different places

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this file you can see the advantage of using the different adapters. Either we route operations to one or the other.

@ulissesferreira
ulissesferreira force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch 2 times, most recently from d163e9c to 0bdab3a Compare August 6, 2026 14:44

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a rename

@ulissesferreira
ulissesferreira force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch 2 times, most recently from 9c70ee3 to a793675 Compare August 6, 2026 15:06
cursoragent and others added 3 commits August 6, 2026 16:32
Match other snaps by listing @metamask/utils under devDependencies so
import-x/no-extraneous-dependencies stays clean without a production dependency.

Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
Remove stale tron-wallet-snap import-x/no-extraneous-dependencies
suppressions now that @metamask/utils is declared.

Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
…ccountAssets

Inject ConfigProvider into SnapAssetsAdapter, fold essential-asset synthesis
into getAccountAssets / getAccountAssetsByScope, and update keyring callers
to use getAccountAssets instead of getByKeyringAccountId.

Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
@cursor
cursor Bot force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch from a793675 to 99fa147 Compare August 6, 2026 16:34

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were importing the configProvider directly from context.ts, which is possible to do, but we want to use dependency injection for more organized code and easier testing

Add CoreAssetsAdapter and mapControllerAsset, and route fungible asset reads
through Core when the Tron assets migration flag is active. Reads stay on the
Snap adapter while migration is off.

Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
@ulissesferreira
ulissesferreira force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch from 99fa147 to 00333d9 Compare August 7, 2026 07:30
gabrieledm
gabrieledm previously approved these changes Aug 7, 2026
this.cacheTtlsMilliseconds = this.#snapAdapter.cacheTtlsMilliseconds;
}

async #getAssetsMigrationStage(): Promise<SnapsAssetsMigrationStage> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: but might simplify a bit if we return a boolean from this method, instead of checking every time if (migrationStage === SnapsAssetsMigrationStage.Off)

}) {
this.#remoteFeatureFlagsProvider = remoteFeatureFlagsProvider;

this.#snapAdapter = new SnapAssetsAdapter({

@taran-a taran-a Aug 7, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like we pass all the dependencies just to instantiate SnapAssetsAdapter, maybe better to instantiate SnapAssetsAdapter outside of AssetsService and simplify this class wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point and that is the correct way to implement the Adapter pattern. What is done there is not right. Will change it ✏️

snapClient,
configProvider,
});
this.#coreAdapter = new CoreAssetsAdapter({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for CoreAssetsAdapter

@ulissesferreira
ulissesferreira force-pushed the ulissesferreira/wpn-1497-core-adapter-routing-9863 branch from 8d32e80 to b472e36 Compare August 7, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants